package com.ruoyi.mall.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mall.mapper.MallCustomerMapper;
import com.ruoyi.mall.domain.MallCustomer;
import com.ruoyi.mall.service.IMallCustomerService;

/**
 * 客户管理Service业务层处理
 * 
 * @author banana_slices
 * @date 2024-12-01
 */
@Service
public class MallCustomerServiceImpl extends ServiceImpl<MallCustomerMapper, MallCustomer> implements IMallCustomerService
{
    @Autowired
    private MallCustomerMapper mallCustomerMapper;

    /**
     * 查询客户管理
     * 
     * @param customerId 客户管理主键
     * @return 客户管理
     */
    @Override
    public MallCustomer selectMallCustomerByCustomerId(Long customerId)
    {
        return mallCustomerMapper.selectMallCustomerByCustomerId(customerId);
    }

    /**
     * 查询客户管理列表
     * 
     * @param mallCustomer 客户管理
     * @return 客户管理
     */
    @Override
    public List<MallCustomer> selectMallCustomerList(MallCustomer mallCustomer)
    {
        return mallCustomerMapper.selectMallCustomerList(mallCustomer);
    }

    /**
     * 新增客户管理
     * 
     * @param mallCustomer 客户管理
     * @return 结果
     */
    @Override
    public int insertMallCustomer(MallCustomer mallCustomer)
    {
        mallCustomer.setCreateTime(DateUtils.getNowDate());
        return mallCustomerMapper.insertMallCustomer(mallCustomer);
    }

    /**
     * 修改客户管理
     * 
     * @param mallCustomer 客户管理
     * @return 结果
     */
    @Override
    public int updateMallCustomer(MallCustomer mallCustomer)
    {
        mallCustomer.setUpdateTime(DateUtils.getNowDate());
        return mallCustomerMapper.updateMallCustomer(mallCustomer);
    }

    /**
     * 批量删除客户管理
     * 
     * @param customerIds 需要删除的客户管理主键
     * @return 结果
     */
    @Override
    public int deleteMallCustomerByCustomerIds(Long[] customerIds)
    {
        return mallCustomerMapper.deleteMallCustomerByCustomerIds(customerIds);
    }

    /**
     * 删除客户管理信息
     * 
     * @param customerId 客户管理主键
     * @return 结果
     */
    @Override
    public int deleteMallCustomerByCustomerId(Long customerId)
    {
        return mallCustomerMapper.deleteMallCustomerByCustomerId(customerId);
    }

    @Override
    public Boolean checkCustomerExist(Long customerId) {
        if (customerId == null) return false;
        //设置查询条件
        LambdaQueryWrapper<MallCustomer> lqw = new LambdaQueryWrapper<>();
        lqw.eq(MallCustomer::getDelFlag, "0");
        lqw.eq(MallCustomer::getCustomerId, customerId);
        //调用查询业务
        return mallCustomerMapper.selectOne(lqw) != null;
    }
}
